<template>
	<view >
		<uni-forms ref="form" :modelValue="form" :rules="rules" :label-width="80" style="background-color: #fff;">
			<uni-forms-item label="监控名称" required name="name">
				<uni-easyinput  v-model="form.name"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="监控IP" required name="monitorIp">
				<uni-easyinput v-model="form.monitorIp"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="监控端口" required name="monitorPort">
				<uni-easyinput v-model="form.monitorPort"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="监控用户名" required name="monitorUsername">
				<uni-easyinput v-model="form.monitorUsername"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="监控密码" required name="monitorPassword">
				<uni-easyinput v-model="form.monitorPassword"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="进出标识" required name="monitorType">
				<uni-data-select v-model="form.monitorType" :localdata="typeOptions" ></uni-data-select>
			</uni-forms-item>
		</uni-forms>
		
	</view>
</template>

<script>
	import {  getMonitor, addMonitor, updateMonitor } from "@/api/control/monitor.js";
	import {  getDicts } from "@/api/system/dict/data"
	export default {
		components: {
		},
		data() {
			return {
				form:{
					id: null,
					name: null,
					monitorIp: null,
					monitorPort: null,
					monitorUsername: null,
					monitorPassword: null,
					monitorType: null,
					monitorUserId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null
				},
				rules:{
					
				},
				typeOptions:[]
			}
		},
		onLoad(options) {
			getDicts('entry_exit_logo').then(res => {
				this.typeOptions = res.data
				this.typeOptions.forEach(d => {
					d.value = d.dictValue
					d.text = d.dictLabel
				})
			})
			if(options.id > 0 ) this.queryById(options.id)
		},
		methods: {
			onNavigationBarButtonTap() {
				this.submitForm()
			},
			queryById(id) {
				getMonitor(id).then(res =>{
					this.form = res.data
				})
			},
			submitForm() {
			 this.$refs.form.validate(['id'],(err,form)=>{
				if (!err) {
				  if (this.form.id != null) {
					updateMonitor(this.form).then(response => {
					  this.$modal.msgSuccess("修改成功");
					  this.isEdit = false
					});
				  } else {
					addMonitor(this.form).then(response => {
					  this.$modal.msgSuccess("新增成功");
					  this.isEdit = false
					});
				  }
				}
			  });
			},
		}
	}
</script>

<style scoped>
page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}
</style>
